/*
 * DesktopApplication1View.java
 */

package robotlion.view;

import java.awt.Dialog.ModalityType;
import java.awt.Image;
import java.awt.Point;
import java.awt.Window;
import java.io.IOException;
import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JFileChooser;
import javax.swing.JRadioButton;
import javax.swing.WindowConstants;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;
import robotlion.model.EDirectionVent;
import sun.swing.SwingAccessor;

/**
 * The application's main frame.
 */
public class RobotLionMainView extends FrameView {

    Action ajoutRobotSimulationClick;
    AjoutTypeRobot f_ajoutTypeRobot;
    AjoutRobot f_ajoutRobotSimulation; 
    // Booléen permettant de déterminer si une  simulation est lancée
    boolean estLance;
    boolean estChargeCarte;
    ListeRobotTableModel modelListeRobot;
    
    private int positionX;
    private int positionY;
    
    private ButtonGroup buttonGroupVent;
    EDirectionVent direction;
    
    // TO DELETE
    int compteurRobot = 0;
    
    
    public RobotLionMainView(SingleFrameApplication app) {
        super(app);
        buttonGroupVent = new ButtonGroup();
        direction = EDirectionVent.SUD;
        
        f_ajoutRobotSimulation = new AjoutRobot(this.getFrame());
        f_ajoutRobotSimulation.setModalityType(ModalityType.APPLICATION_MODAL);
        f_ajoutRobotSimulation.setLocationRelativeTo(getRootPane());
        
        initComponents();
        
        buttonGroupVent.add(jRadioButtonNord);
        buttonGroupVent.add(jRadioButtonSud);
        buttonGroupVent.add(jRadioButtonEst);
        buttonGroupVent.add(jRadioButtonOuest);
        
        jRadioButtonNord.setActionCommand("Nord");
        jRadioButtonSud.setActionCommand("Sud");
        jRadioButtonEst.setActionCommand("Est");
        jRadioButtonOuest.setActionCommand("Ouest");
        
        
        f_ajoutTypeRobot = new AjoutTypeRobot(getFenetreCarte().getMyJDOM());
        f_ajoutTypeRobot.setLocationRelativeTo(getRootPane());
        estLance = false;
        estChargeCarte = false;
        
        modelListeRobot = new ListeRobotTableModel();
        jTableListeRobot.setModel(modelListeRobot); 
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButtonDelRobot = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButtonLancerSimu = new javax.swing.JButton();
        fenetreCarte = (FenetreRobotLion)fenetreCarte;
        fenetreCarte = new FenetreRobotLion();
        btnChargerCarte = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableListeRobot = new javax.swing.JTable();
        jButtonPause = new javax.swing.JButton();
        jButtonAccelerer = new javax.swing.JButton();
        jLabelOrientationVent = new javax.swing.JLabel();
        jSpinnerForceVent = new javax.swing.JSpinner();
        jButtonStopSimu = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jRadioButtonSud = new javax.swing.JRadioButton();
        jRadioButtonEst = new javax.swing.JRadioButton();
        jRadioButtonOuest = new javax.swing.JRadioButton();
        jRadioButtonNord = new javax.swing.JRadioButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        jMenuGestionRobot = new javax.swing.JMenu();
        jMenuNewSimu = new javax.swing.JMenu();
        jPopupMenuAjoutCarte = new javax.swing.JPopupMenu();
        jMenuItemAddRobot = new javax.swing.JMenuItem();
        jMenuItemAddIncendie = new javax.swing.JMenuItem();
        jMenuItemDelIncendie = new javax.swing.JMenuItem();
        jFileChooserImage = new javax.swing.JFileChooser();

        mainPanel.setName("mainPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(robotlion.view.RobotLion.class).getContext().getResourceMap(RobotLionMainView.class);
        jButtonDelRobot.setText(resourceMap.getString("jButtonDelRobot.text")); // NOI18N
        jButtonDelRobot.setName("jButtonDelRobot"); // NOI18N
        jButtonDelRobot.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonDelRobotMouseClicked(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jButtonLancerSimu.setIcon(resourceMap.getIcon("jButtonLancerSimu.icon")); // NOI18N
        jButtonLancerSimu.setName("jButtonLancerSimu"); // NOI18N
        jButtonLancerSimu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonLancerSimuMouseClicked(evt);
            }
        });

        fenetreCarte.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        fenetreCarte.setName("fenetreCarte"); // NOI18N
        fenetreCarte.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                carteMouseClicked(evt);
            }
        });

        btnChargerCarte.setText(resourceMap.getString("btnChargerCarte.text")); // NOI18N
        btnChargerCarte.setName("btnChargerCarte"); // NOI18N
        btnChargerCarte.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnChargerCarteClick(evt);
            }
        });

        javax.swing.GroupLayout fenetreCarteLayout = new javax.swing.GroupLayout(fenetreCarte);
        fenetreCarte.setLayout(fenetreCarteLayout);
        fenetreCarteLayout.setHorizontalGroup(
            fenetreCarteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fenetreCarteLayout.createSequentialGroup()
                .addGap(135, 135, 135)
                .addComponent(btnChargerCarte)
                .addContainerGap(148, Short.MAX_VALUE))
        );
        fenetreCarteLayout.setVerticalGroup(
            fenetreCarteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fenetreCarteLayout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addComponent(btnChargerCarte)
                .addContainerGap(181, Short.MAX_VALUE))
        );

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTableListeRobot.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Robot", "Etat"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableListeRobot.setName("jTableListeRobot"); // NOI18N
        jTableListeRobot.getTableHeader().setReorderingAllowed(false);
        jScrollPane3.setViewportView(jTableListeRobot);
        jTableListeRobot.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTableListeRobot.columnModel.title0")); // NOI18N
        jTableListeRobot.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTableListeRobot.columnModel.title1")); // NOI18N

        jButtonPause.setIcon(resourceMap.getIcon("jButtonPause.icon")); // NOI18N
        jButtonPause.setEnabled(false);
        jButtonPause.setName("jButtonPause"); // NOI18N

        jButtonAccelerer.setIcon(resourceMap.getIcon("jButtonAccelerer.icon")); // NOI18N
        jButtonAccelerer.setEnabled(false);
        jButtonAccelerer.setName("jButtonAccelerer"); // NOI18N

        jLabelOrientationVent.setText(resourceMap.getString("jLabelOrientationVent.text")); // NOI18N
        jLabelOrientationVent.setName("jLabelOrientationVent"); // NOI18N

        jSpinnerForceVent.setModel(new javax.swing.SpinnerNumberModel(0, 0, 200, 1));
        jSpinnerForceVent.setToolTipText(resourceMap.getString("jSpinnerForceVent.toolTipText")); // NOI18N
        jSpinnerForceVent.setName("jSpinnerForceVent"); // NOI18N
        jSpinnerForceVent.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinnerForceVentStateChanged(evt);
            }
        });

        jButtonStopSimu.setIcon(resourceMap.getIcon("jButtonStop.icon")); // NOI18N
        jButtonStopSimu.setName("jButtonStop"); // NOI18N
        jButtonStopSimu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonStopClick(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jRadioButtonSud.setSelected(true);
        jRadioButtonSud.setText(resourceMap.getString("jRadioButtonSud.text")); // NOI18N
        jRadioButtonSud.setName("jRadioButtonSud"); // NOI18N
        jRadioButtonSud.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButtonItemStateChanged(evt);
            }
        });

        jRadioButtonEst.setText(resourceMap.getString("jRadioButtonEst.text")); // NOI18N
        jRadioButtonEst.setName("jRadioButtonEst"); // NOI18N
        jRadioButtonEst.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButtonItemStateChanged(evt);
            }
        });

        jRadioButtonOuest.setText(resourceMap.getString("jRadioButtonOuest.text")); // NOI18N
        jRadioButtonOuest.setName("jRadioButtonOuest"); // NOI18N
        jRadioButtonOuest.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButtonItemStateChanged(evt);
            }
        });

        jRadioButtonNord.setText(resourceMap.getString("jRadioButtonNord.text")); // NOI18N
        jRadioButtonNord.setName("jRadioButtonNord"); // NOI18N
        jRadioButtonNord.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButtonItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(fenetreCarte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(jButtonLancerSimu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonPause)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonAccelerer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonStopSimu))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelOrientationVent)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jRadioButtonSud)
                                .addGap(18, 18, 18)
                                .addComponent(jRadioButtonNord)))
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButtonEst)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButtonOuest)
                        .addGap(8, 8, 8)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jSpinnerForceVent)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButtonDelRobot, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(11, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabelOrientationVent))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinnerForceVent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButtonSud)
                    .addComponent(jRadioButtonEst)
                    .addComponent(jRadioButtonOuest)
                    .addComponent(jRadioButtonNord))
                .addGap(18, 18, 18)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fenetreCarte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE)))
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jButtonDelRobot)
                        .addGap(10, 10, 10))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonPause, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonLancerSimu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonAccelerer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonStopSimu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(284, 284, 284))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(robotlion.view.RobotLion.class).getContext().getActionMap(RobotLionMainView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenuGestionRobot.setText(resourceMap.getString("jMenuGestionRobot.text")); // NOI18N
        jMenuGestionRobot.setName("jMenuGestionRobot"); // NOI18N
        jMenuGestionRobot.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GestionTypeRobotClick(evt);
            }
        });
        menuBar.add(jMenuGestionRobot);

        jMenuNewSimu.setText(resourceMap.getString("jMenuNewSimu.text")); // NOI18N
        jMenuNewSimu.setName("jMenuNewSimu"); // NOI18N
        jMenuNewSimu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuNewSimuMouseClicked(evt);
            }
        });
        menuBar.add(jMenuNewSimu);

        jPopupMenuAjoutCarte.setName("jPopupMenuAjoutCarte"); // NOI18N

        jMenuItemAddRobot.setAction(ajoutRobotSimulationClick);
        jMenuItemAddRobot.setText(resourceMap.getString("jMenuItemAddRobot.text")); // NOI18N
        jMenuItemAddRobot.setName("jMenuItemAddRobot"); // NOI18N
        jMenuItemAddRobot.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemAjoutRobotActionPerformed(evt);
            }
        });
        jPopupMenuAjoutCarte.add(jMenuItemAddRobot);

        jMenuItemAddIncendie.setLabel(resourceMap.getString("jMenuItemAddIncendie.label")); // NOI18N
        jMenuItemAddIncendie.setName("jMenuItemAddIncendie"); // NOI18N
        jMenuItemAddIncendie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemAjoutIncendie(evt);
            }
        });
        jPopupMenuAjoutCarte.add(jMenuItemAddIncendie);

        jMenuItemDelIncendie.setText(resourceMap.getString("jMenuItemDelIncendie.text")); // NOI18N
        jMenuItemDelIncendie.setLabel(resourceMap.getString("jMenuItemDelIncendie.label")); // NOI18N
        jMenuItemDelIncendie.setName("jMenuItemDelIncendie"); // NOI18N
        jMenuItemDelIncendie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemDelIncendieActionPerformed(evt);
            }
        });
        jPopupMenuAjoutCarte.add(jMenuItemDelIncendie);

        jFileChooserImage.setName("jFileChooserImage"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void GestionTypeRobotClick(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_GestionTypeRobotClick
        f_ajoutTypeRobot.setVisible(true);
    }//GEN-LAST:event_GestionTypeRobotClick

    private void carteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_carteMouseClicked
        if(estChargeCarte && !estLance)
        {
            jPopupMenuAjoutCarte.show(evt.getComponent(), evt.getX(), evt.getY());
            positionX = evt.getX();
            positionY = evt.getY();
        }
    }//GEN-LAST:event_carteMouseClicked

    private void jMenuItemAjoutRobotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAjoutRobotActionPerformed
        f_ajoutRobotSimulation.setJComboBox1(((FenetreRobotLion)fenetreCarte).getMyJDOM().getListRobot());
        f_ajoutRobotSimulation.setVisible(true);
       
        if(f_ajoutRobotSimulation.getIsAjouterClicked())
        {
            getFenetreCarte().getController().addRobot(f_ajoutRobotSimulation.getSelectedName()+compteurRobot++,
                f_ajoutRobotSimulation.getSelectedVitesseRobot(),
                new Point(positionX/20, positionY/20),
                f_ajoutRobotSimulation.getSelectedNiveauAccessibilityRobot(),
                1,
                new RobotVue(modelListeRobot, getFenetreCarte()));
        }
    }//GEN-LAST:event_jMenuItemAjoutRobotActionPerformed

    private void jButtonLancerSimuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonLancerSimuMouseClicked
        if (!estLance && estChargeCarte)
        {
            ((FenetreRobotLion)fenetreCarte).getController().lancerSimulation(this);
            estLance = true;
        }
    }//GEN-LAST:event_jButtonLancerSimuMouseClicked

    private void btnChargerCarteClick(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnChargerCarteClick
        JFileChooser selection = new JFileChooser(".");

        FileFilter imagesFilter = new FileNameExtensionFilter("Images", "bmp", "gif", "jpg", "jpeg", "png");
        selection.setFileFilter(imagesFilter);
        int result = selection.showOpenDialog(null);

        if(result == JFileChooser.APPROVE_OPTION)
        {
            try {
                Image bg = ((FenetreRobotLion)fenetreCarte).getController().initCarte(selection.getSelectedFile(), getFenetreCarte());
                
                btnChargerCarte.setVisible(false);
                ((FenetreRobotLion)fenetreCarte).setBackground(bg);
                estChargeCarte = true;
            } catch (IOException ex) {
                btnChargerCarte.setVisible(true);
            }
        }
    }//GEN-LAST:event_btnChargerCarteClick

    private void jMenuItemAjoutIncendie(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAjoutIncendie
        getFenetreCarte().getController().addIncendie(new Point(positionX/20, positionY/20),10);
    }//GEN-LAST:event_jMenuItemAjoutIncendie

private void jButtonStopClick(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonStopClick
    if (estLance && estChargeCarte)
        {
            getFenetreCarte().getController().arreter();
            estLance = false;
        }    
}//GEN-LAST:event_jButtonStopClick

    private void jSpinnerForceVentStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinnerForceVentStateChanged
        getFenetreCarte().getController().setEnvironnement((int)jSpinnerForceVent.getValue(), direction);
    }//GEN-LAST:event_jSpinnerForceVentStateChanged

    private void jRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButtonItemStateChanged
        ButtonModel selectedButton = buttonGroupVent.getSelection();
        if(selectedButton != null)
        {
            switch(selectedButton.getActionCommand())
            {
                case "Nord":
                    direction = EDirectionVent.NORD;
                    break;
                case "Sud":
                    direction = EDirectionVent.SUD;
                    break;
                case "Est":
                    direction = EDirectionVent.EST;
                    break;
                case "Ouest":
                    direction = EDirectionVent.OUEST;
                    break;
            }
            getFenetreCarte().getController().setEnvironnement((int)jSpinnerForceVent.getValue(), direction);
        }
    }//GEN-LAST:event_jRadioButtonItemStateChanged

    private void jButtonDelRobotMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonDelRobotMouseClicked
        if (!estLance)
        {
            int rownum = jTableListeRobot.getSelectedRow();
            String nomRobot = modelListeRobot.getNomRobot(rownum);
            this.getFenetreCarte().getController().delRobot(nomRobot);
        }
    }//GEN-LAST:event_jButtonDelRobotMouseClicked

    private void jMenuNewSimuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuNewSimuMouseClicked
        // Lance une nouvelle instance du simulateur
        RobotLion.launch(RobotLion.class, null);
        // Detruit l'instance courante
        this.getFrame().dispose();
    }//GEN-LAST:event_jMenuNewSimuMouseClicked

    private void jMenuItemDelIncendieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemDelIncendieActionPerformed
        getFenetreCarte().getController().delIncendie(new Point(positionX/20, positionY/20),10);
    }//GEN-LAST:event_jMenuItemDelIncendieActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChargerCarte;
    private javax.swing.JPanel fenetreCarte;
    private javax.swing.JButton jButtonAccelerer;
    private javax.swing.JButton jButtonDelRobot;
    private javax.swing.JButton jButtonLancerSimu;
    private javax.swing.JButton jButtonPause;
    private javax.swing.JButton jButtonStopSimu;
    private javax.swing.JFileChooser jFileChooserImage;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelOrientationVent;
    private javax.swing.JMenu jMenuGestionRobot;
    private javax.swing.JMenuItem jMenuItemAddIncendie;
    private javax.swing.JMenuItem jMenuItemAddRobot;
    private javax.swing.JMenuItem jMenuItemDelIncendie;
    private javax.swing.JMenu jMenuNewSimu;
    private javax.swing.JPopupMenu jPopupMenuAjoutCarte;
    private javax.swing.JRadioButton jRadioButtonEst;
    private javax.swing.JRadioButton jRadioButtonNord;
    private javax.swing.JRadioButton jRadioButtonOuest;
    private javax.swing.JRadioButton jRadioButtonSud;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSpinner jSpinnerForceVent;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTableListeRobot;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables

    public FenetreRobotLion getFenetreCarte() {
        return (FenetreRobotLion)fenetreCarte;
    }
}
